package qianting.news.article.feign;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import qianting.news.apis.models.article.dtos.ArticleCommentDto;
import qianting.news.apis.models.article.dtos.ArticleDto;
import qianting.news.apis.models.article.dtos.CommentConfigDto;
import qianting.news.apis.models.article.dtos.StatisticsDto;
import qianting.news.apis.models.article.pojos.ApArticleConfig;
import qianting.news.apis.services.article.IArticleClient;
import qianting.news.article.service.ApArticleConfigService;
import qianting.news.article.service.ApArticleService;
import qianting.news.common.entity.State;

import java.util.Date;

@Api(tags = "api管理")
@RestController
@RequestMapping("/api")
public class ArticleClient implements IArticleClient {

    @Autowired
    private ApArticleService apArticleService;

    @Autowired
    private ApArticleConfigService apArticleConfigService;

    @ApiOperation(value = "保存文章")
    @Override
    @PostMapping("save")
    public State saveArticle(ArticleDto dto) {
        return apArticleService.saveArticle(dto);
    }

    //(查询某个作者所有的文章的被喜欢数,被收藏数,总数)
    @ApiOperation(value = "查询某个作者所有的文章的被喜欢数,被收藏数,总数")
    @Override
    @GetMapping("queryLikesAndConllections")
    public State queryLikesAndConllections(Long wmUserId, Date beginDate, Date endDate) {
        return apArticleService.queryLikesAndConllections(wmUserId,beginDate,endDate);
    }

    //分页查询某个作者的所有文章行为信息(id,标题,行为数)
    @ApiOperation(value = "分页查询某个作者的所有文章行为信息(id,标题,行为数)")
    @Override
    @PostMapping("newPage")
    public State newPage(StatisticsDto dto) {
        return apArticleService.newPage(dto);
    }

    //查询某个文章的具体配置信息(上下架,允许评论)
    @ApiOperation(value = "查询某个文章的具体配置信息(上下架,允许评论)")
    @Override
    @GetMapping("findArticleConfigByArticleId/{articleId}")
    public State findArticleConfigByArticleId(Long articleId) {
        ApArticleConfig apArticleConfig = apArticleConfigService.getOne(Wrappers.<ApArticleConfig>lambdaQuery().eq(ApArticleConfig::getArticleId, articleId));
        return State.succ(apArticleConfig);
    }

    //查看当前用户可以评论的文章
    @ApiOperation(value = "查看当前用户可以评论的文章")
    @Override
    @PostMapping("findNewsComments")
    public State findNewsComments(ArticleCommentDto dto) {
        return apArticleService.findNewsComments(dto);
    }

    //修改文章评论状态
    @ApiOperation(value = "修改文章评论状态")
    @Override
    @PostMapping("updateCommentStatus")
    public State updateCommentStatus(CommentConfigDto dto) {
        return apArticleConfigService.updateCommentStatus(dto);
    }
}
